package com.xh.hongaicodegenerator.core.saver;

import com.xh.hongaicodegenerator.ai.genresult.HtmlCodeResult;
import com.xh.hongaicodegenerator.ai.genresult.MultiFileCodeResult;
import com.xh.hongaicodegenerator.exception.BusinessException;
import com.xh.hongaicodegenerator.exception.ErrorCode;
import com.xh.hongaicodegenerator.model.enums.CodeGenTypeEnum;

import java.io.File;

/**
 * 代码文件保存执行器
 * 门面模式：将多个功能封装成多个类，通过一个类进行调用
 */
public class CodeFileSaverExecutor {
    private final static HtmlCodeFileSaver htmlCodeFileSaver = new HtmlCodeFileSaver();
    private final static MultiCodeFileSaver multiCodeFileSaver=new MultiCodeFileSaver();

    public static File saveCode(Object result, CodeGenTypeEnum codeGenTypeEnum, Long appId){
        return switch(codeGenTypeEnum){
            case HTML -> htmlCodeFileSaver.saveCode((HtmlCodeResult) result, appId);
            case MULTI_FILE -> multiCodeFileSaver.saveCode((MultiFileCodeResult) result, appId);
            default -> throw new BusinessException(ErrorCode.SYSTEM_ERROR, "不支持的代码生成类型");
        };
    }

}
